#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct stud
{char nume[20];
 char prenume[20];
 int grupa;
 int id;
}stud;
typedef struct li
{stud v;
li *next;
}li;
li *p=NULL;
void add(char *_nume,char *_prenume,int _grupa,int _id)
{ 
	li *s,*q;
    s=(li *)malloc(sizeof(li));
    strcpy(s->v.nume,_nume);
    strcpy(s->v.prenume,_prenume);
    s->v.grupa=_grupa; 
    s->v.id=_id;
    s->next=NULL;
  if(p==NULL)
	p=s;
  else
    {
	 q=p;
	  while(q->next)
	    q=q->next;
     q->next=s;  
    }
}
void afisare()
{
	li *q=p;
   while(q!=NULL)
    {
		printf("%s ",q->v.nume);
        printf("%s ",q->v.prenume);
        printf("%d ",q->v.grupa);
        printf("%d \n",q->v.id);
      q=q->next;
    }
}
void freelist()
{
	if(p==NULL)
    return;
  li *aux;
  while(p)
  {
	  aux=p->next;
      free(p);
      p=aux;
  }
}
void deletestd()
{
	li *crt=p,*q;
   if(!p)
	return;
   while((crt->v.id)%2==0)
    {
		p=crt->next;
        free(crt);
        crt=p;
        if(crt==NULL)
	     return;
    }
 
  while(crt->next)
    { 
	 if((crt->next->v.id)%2==0)
       {  
         q=crt->next;
         crt->next=q->next;
         free(q);
      } 
     else
         crt=crt->next; 
 }
}
    
void main()
{
	char *t1,*t2,*t3,*t4;
    int m,n;
    char s[64];
    FILE *f=fopen("in.txt","r");
   if(!f)
     {
		 printf("eroare la deschidere!");
         return;
     }
   while(fgets(s,sizeof(s),f)!=NULL)
     {
		 t1=strtok(s," \n");
         t2=strtok(NULL," \n");
         t3=strtok(NULL," \n");
         m=atoi(t3);
         t4=strtok(NULL," \n");
         n=atoi(t4);
         add(t1,t2,m,n);
     }
   fclose(f);
   afisare();
   deletestd();
   printf("\n-------------------\n");
   afisare();
   freelist();
}
